//
//  LoginViewController.swift
//  构建协调器
//
//  Created by 姚晓俊 on 2019/1/7.
//  Copyright © 2019 姚晓俊. All rights reserved.
//

import UIKit
import SnapKit
import RxSwift
import RxCocoa

class LoginViewController: UIViewController {

    var textField: UITextField?
    var tipsLabel: UILabel?
    var maxTipsLabel: UILabel?
    var confirmButton: UIButton?
    var viewModel: LoginVM?
    
    private let disposeBag = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        self.setupUI()
        viewModel = LoginVM()
        self.binding()
        
    }
    
    
    private func setupUI() -> Void {
        let textField = UITextField()
        view.addSubview(textField)
        textField.backgroundColor = .yellow
        textField.snp.makeConstraints { (m) in
            m.top.equalToSuperview().offset(300)
            m.centerX.equalToSuperview()
            m.width.equalTo(200)
            m.height.equalTo(34)
        }
        self.textField = textField
        let tipsLabel = UILabel()
        view.addSubview(tipsLabel)
        tipsLabel.snp.makeConstraints { (m) in
            m.bottom.equalTo(textField.snp.top).offset(-20)
            m.left.equalTo(textField)
            m.height.equalTo(20)
        }
        tipsLabel.text = "用户名不能少于4位"
        self.tipsLabel = tipsLabel
        
        let maxTipsLabel = UILabel()
        view.addSubview(maxTipsLabel)
        maxTipsLabel.snp.makeConstraints { (m) in
            m.bottom.equalTo(textField.snp.bottom).offset(20)
            m.left.equalTo(textField)
            m.height.equalTo(20)
        }
        maxTipsLabel.text = "用户名不能多于8位"
        self.maxTipsLabel = maxTipsLabel
        
        let btn = UIButton()
        btn.setTitleColor(.black, for: .normal)
        btn.setTitle("确认", for: .normal)
        view.addSubview(btn)
        btn.snp.makeConstraints { (m) in
            m.top.equalTo(maxTipsLabel.snp.bottom).offset(20)
            m.centerX.equalToSuperview()
            m.size.equalTo(CGSize(width: 200, height: 100))
        }
        btn.backgroundColor = .red
        
        self.confirmButton = btn
    }
    

    private func binding() -> Void {
//        viewModel?.tipsObservable.bind(to: tipsLabel?.rx.isHidden)
//        viewModel?.tipsObservable.bind(to: tipsLabel?.rx.isHidden).disposed(by: disposeBag)
        
        viewModel?.textObservable.bind(to: rx.title).disposed(by: disposeBag)
    }
    
    


}
